<?php
$post = $_POST;
try {
    if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
        $tmpName = $_FILES['file']['tmp_name'];
        $fileName = $tmpName;
        $currentDir = './';
        $targetName = $currentDir.$_FILES['file']['name'];
        $_res = exec("cp $fileName $targetName", $cp_res, $cp_res_code);
        if ($cp_res) {
            echo json_encode([
                'code' => 0, 'msg' => '文件移动失败 请检查权限问题'.json_encode($cp_res).' cmd:'."cp $fileName $targetName", 'filePath' => $fileName, 'targetName' => $targetName,
            ]);exit;
        }
        if (file_exists($fileName)) {
            unlink($fileName);
        }
        exec("chmod 755 $targetName");
        echo json_encode([
            'code' => 1, 'msg' => 'success', 'filePath' => $finalFileName,
        ]);exit;
    } else {
        echo json_encode([
            'code' => 0, 'msg' => '文件不存在', 'detail' => 'fail',
        ]);exit;
    }
} catch (\Throwable $th) {
    echo $th->getMessage();
    var_dump($th->getTraceAsString());
}
exit;    
?>
